﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace BookTheBook.Web.Helpers
{
    public class PaginatedListCollection<T> : List<T>
    {
        public int PageNumber { get; private set; }
        public int PageSize { get; private set; }
        public int ItemsCount { get; private set; }
        public int PagesCount { get; private set; }
        public string Query { get; private set; }

        public PaginatedListCollection(IEnumerable<T> books, int pageNumber, int pageSize)
        {
            PageNumber = pageNumber;
            PageSize = pageSize;
            ItemsCount = books.Count();
            PagesCount = (int)Math.Ceiling((double)ItemsCount/(double)pageSize);

            AddRange(books.Skip(pageNumber*pageSize).Take(pageSize));
        }

        public PaginatedListCollection(IEnumerable<T> collection, int pagesCount, string query, int pageNumber) : base(collection)
        {
            PagesCount = pagesCount;
            Query = query;
            PageNumber = pageNumber;
        }
    }
}
